﻿function showMsg(mid) {
	if (refreshWin('showMsg' + mid)) return;
	getMsg({
				mid : mid,
				success : onload
			});

	function onload(data) {
		if (!data.read) {
			var refreshtask = new Ext.util.DelayedTask(refreshTab, this, ['showMsgBox_'
							+ sys.user.username]);
			refreshtask.delay(1500);
		}

		var from = new Ext.form.TextField({
					fieldLabel : '发件人',
					value : sys.rd.authorusername(data),
					anchor : '95%',
					readOnly : true
				});
		var title = new Ext.form.TextField({
					fieldLabel : '主题',
					value : data.title,
					anchor : '95%',
					readOnly : true
				});
		var time = new Ext.form.TextField({
					fieldLabel : '发送时间',
					value : data.time,
					anchor : '95%',
					readOnly : true
				});
		var content = new Ext.ux.HtmlViewer({
					fieldLabel : '内容',
					value : data.content,
					anchor : '95% -80'
				});

		var form = new Ext.FormPanel({
					frame : true,
					labelAlign : 'right',
					labelWidth : 60,
					buttonAlign : 'left',
					bodyStyle : 'padding-top:5px',
					items : [from, title, time, content],
					fbar : new Ext.Toolbar({
								items : [new Ext.Button({
													text : '回复',
													iconCls : 'replymail-icon',
													handler : function() {
														sendMsg({
																	username : data.username,
																	title : 're:' + data.title
																});
														win.close();
													},
													disabled : !sys.canSendMsg
												}), new Ext.Button({
													text : '删除',
													iconCls : 'delete-icon',
													handler : function() {
														deleteMsg({
																	mid : data.mid,
																	title : data.title,
																	success : function() {
																		win.close();
																	}
																})
													}
												}), new Ext.Toolbar.Fill(), new Ext.Button({
													text : '关闭',
													iconCls : 'ok-icon',
													handler : function() {
														win.close();
													}
												})]
							})
				});
		var win = new Ext.Window({
					id : 'showMsg' + mid,
					title : '查看消息',
					iconCls : 'mail-icon',					layout : 'fit',
					width : 650,
					height : 350,
					minWidth : 400,
					minHeight : 250,
					items : form
				});
		win.show();
	}
}

function getMsg(obj) {
	ajax({
				url : url.getMsg,
				params : {
					mid : obj.mid
				},
				success : obj.success
			});
}